package com.khyr.controller;


import com.khyr.entity.Dept;
import com.khyr.feign.UserFeign;
import com.khyr.service.SchedulingService;
import com.khyr.vo.R;
import com.khyr.vo.SaveSchedulingVo;
import com.khyr.vo.SchedulingVo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/seeADoctor/scheduling")
public class SchedulingController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserFeign userFeign;

    @Autowired
    private SchedulingService schedulingService;

    /**
     * @create by: Zr
     * @description: 根据条件查询值班医生，调用了services-system中的getSchedulingDoctorByCon
     * @create time: 2025/3/14 11:38
     * @param vo
     * @return com.khyr.vo.R<java.util.Map<java.lang.String,java.lang.Object>>
     */
    @PostMapping("/docter")
    public R<Map<String,Object>> docter(@RequestBody SchedulingVo vo){
        return schedulingService.docterScheduling(vo);
    }
    /**
     * @create by: Zr
     * @description: 查询所有可用科室的信息
     * @create time: 2025/3/13 14:36
     * @param
     * @return com.khyr.vo.R<java.util.List<com.khyr.entity.Dept>>
     */
    @GetMapping("/getDeptList")
    public R<List<Dept>> getDeptList(){
        return schedulingService.getDeptList();
    }
    /**
     * @create by: Zr
     * @description: 根据前端传入的数据，根据日期和userId删除排班，再重新添加排班
     * @create time: 2025/3/13 15:46
     * @param vo
     * @return com.khyr.vo.R<java.lang.String>
     */
    @PostMapping("/saveScheduling")
    public R<String> saveScheduling(@RequestBody SaveSchedulingVo vo){
        String token = request.getHeader("token");
        String name=userFeign.getUserInfo(token).getData().getUserName();
        return schedulingService.saveScheduling(vo,name);
    }
    /**
     * @create by: Zr
     * @description: 我的排班，根据UserId查询排班信息
     * @create time: 2025/3/14 15:27
     * @param vo
     * @return com.khyr.vo.R<java.util.Map<java.lang.String,java.lang.Object>>
     */
    @PostMapping("/queryMyScheduling")
    public R<Map<String,Object>> queryMyScheduling(@RequestBody SchedulingVo vo){
        if(vo.getUserId()==null){
            String token = request.getHeader("token");
            Long name=userFeign.getUserInfo(token).getData().getUserId();
            vo.setUserId(Math.toIntExact(name));
        }
        return schedulingService.docterScheduling(vo);
    }
}
